/*
    SUSAN® - Sole of Unix Save ANything

   

   
*/
#include <stdio.h>
#include "include/config.h"
#include "version.h"
#include "osinfo.h"

#if !defined SUSAN_VERSION
#warning should define SUSAN_VERSION when building version.c
#define SUSAN_VERSION "x.y.z"
#endif

#if !defined SUSAN_DATE
#warning should define SUSAN_DATE when building version.c
#define SUSAN_DATE "unknown date"
#endif

#if !defined SUSAN_SHORT_DATE
#warning should define SUSAN_SHORT_DATE when building version.c
#define SUSAN_SHORT_DATE "unknown date"
#endif

#if !defined SUSAN_PROG_DATE_TIME
#warning should define SUSAN_PROG_DATE_TIME when building version.c
#define SUSAN_PROG_DATE_TIME __DATE__ " " __TIME__
#endif

#if !defined SUSAN_YEAR
#warning should define SUSAN_YEAR when building version.c
#define SUSAN_YEAR "2019"
#endif

#if !defined SUSAN_BINARY_INFO
#define SUSAN_BINARY_INFO "self-compiled"
#endif

#if !defined SUSAN_SERVICES_MESSAGE
#define SUSAN_SERVICES_MESSAGE                             \
  "self-compiled binaries are UNSUPPORTED by skyatlas.net.\n" \
  "Get official binaries and vendor support on https://www.skyatlas.net"
#endif

#if !defined SUSAN_JOBLOG_MESSAGE
#define SUSAN_JOBLOG_MESSAGE \
  "self-compiled: Get official binaries and vendor support on skyatlas.net"
#endif

#define SUSAN_COPYRIGHT_MESSAGE_WITH_FSF_AND_PLANETS            \
  "\n%s"                                                         \
  "\n"                                                           \
  "Copyright (C) 2013-%s Hechzh Property\n"                 \
  "Copyright (C) %d-2012 Hechzh Property\n" \
  "Copyright (C) 2010-2017 Skyatlas Co. CN\n"        \
  "\n"                                                           \
  "Version: %s (%s) %s\n"                                        \
  "\n"

#if defined(HAVE_WIN32)
char win_os[300];
#endif

static void FormatCopyrightWithFsfAndPlanets(char* out, size_t len, int FsfYear)
{
  snprintf(out, len, SUSAN_COPYRIGHT_MESSAGE_WITH_FSF_AND_PLANETS,
           kSusanVersionStrings.ServicesMessage, kSusanVersionStrings.Year,
           FsfYear, kSusanVersionStrings.Full, kSusanVersionStrings.Date,
           kSusanVersionStrings.GetOsInfo());
}
static void PrintCopyrightWithFsfAndPlanets(FILE* fh, int FsfYear)
{
  fprintf(fh, SUSAN_COPYRIGHT_MESSAGE_WITH_FSF_AND_PLANETS,
          kSusanVersionStrings.ServicesMessage, kSusanVersionStrings.Year,
          FsfYear, kSusanVersionStrings.Full, kSusanVersionStrings.Date,
          kSusanVersionStrings.GetOsInfo());
}


#define SUSAN_COPYRIGHT_MESSAGE               \
  "\n%s"                                       \
  "\n"                                         \
  "Copyright (C) %d-%s Hechzh Property\n" \
  "\n"                                         \
  "Version: %s (%s) %s\n"                      \
  "\n"

static void FormatCopyright(char* out, size_t len, int StartYear)
{
  snprintf(out, len, SUSAN_COPYRIGHT_MESSAGE,
           kSusanVersionStrings.ServicesMessage, StartYear,
           kSusanVersionStrings.Year, kSusanVersionStrings.Full,
           kSusanVersionStrings.Date, kSusanVersionStrings.GetOsInfo());
}
static void PrintCopyright(FILE* fh, int StartYear)
{
  fprintf(fh, SUSAN_COPYRIGHT_MESSAGE, kSusanVersionStrings.ServicesMessage,
          StartYear, kSusanVersionStrings.Year, kSusanVersionStrings.Full,
          kSusanVersionStrings.Date, kSusanVersionStrings.GetOsInfo());
}

const struct SusanVersionStrings kSusanVersionStrings = {
    .Full = SUSAN_VERSION,
    .Date = SUSAN_DATE,
    .ShortDate = SUSAN_SHORT_DATE,
    .ProgDateTime = SUSAN_PROG_DATE_TIME,
    .FullWithDate = SUSAN_VERSION " (" SUSAN_DATE ")",
    .Year = SUSAN_YEAR,
    .BinaryInfo = SUSAN_BINARY_INFO,
    .ServicesMessage = SUSAN_SERVICES_MESSAGE,
    .JoblogMessage = SUSAN_JOBLOG_MESSAGE,
    .FormatCopyrightWithFsfAndPlanets = FormatCopyrightWithFsfAndPlanets,
    .PrintCopyrightWithFsfAndPlanets = PrintCopyrightWithFsfAndPlanets,
    .FormatCopyright = FormatCopyright,
    .PrintCopyright = PrintCopyright,
    .GetOsInfo = GetOsInfoString};
